package com.lz.sports.db

import androidx.room.*
import com.lz.sports.bean.DeviceGroup
import com.lz.sports.bean.DeviceGroupWithInfo

@Dao
interface DeviceGroupDao {

    //插入一组
    @Insert
    fun insert(group: DeviceGroup): Long

    @Query("select * from DeviceGroup where id = :id")
    fun findDeviceGroupById(id: Int): DeviceGroup?

    //查找所有组带设备信息
    @Transaction
    @Query("select * from DeviceGroup where projectId = :projectId")
    fun deviceGroupListWithInfo(projectId: Int): List<DeviceGroupWithInfo>

    //查找所有组
    @Query("select * from DeviceGroup where projectId = :projectId")
    fun deviceGroupList(projectId: Int): List<DeviceGroup>









    //查找所有组
    @Transaction
    @Query("select * from DeviceGroup")
    fun deviceGroupListWithInfo(): List<DeviceGroupWithInfo>

    //查找设备组并关联设备信息
    @Transaction
    @Query("select * from DeviceGroup where id = :groupId")
    fun findDeviceGroup(groupId: Int): DeviceGroupWithInfo?

    //删除组
    @Query("delete from DeviceGroup where id = :id")
    fun deleteGroup(id: Int)

    //修改组名
    @Query("update DeviceGroup set name = :name where id = :id")
    fun modifyGroupName(name: String, id: Int)

    //更新组状态
    @Update
    fun updateGroup(group: DeviceGroup): Int

    //取消该组所有绑定
    @Query("update DeviceGroup set numbers = 0 where id = :id")
    fun unbindGroup(id: Int)
}